<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
/**
 * Football Referees extension for Joomleague
 * @version $Id:controller.php 95 2008-02-22 21:04:45Z julien.vonthron $
 * @package JlgFootballReferees
 * @copyright Copyright (C) 2007 Julien Vonthron. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * JlgFootballReferees is free software and parts of it may contain or be derived from the
 * GNU General Public License or other free or open source software licenses.
 * 
 * contact: julien.vonthron[at]gmail.com 
 *   
 * Joomleague is a League Management and Prediction Game for Joomla!
 * Homepage: http://www.joomleague.de 
 *  
 */

// Language selection - START
if (file_exists(JL_TEMPLATE_PATH.'/language/'._JL_LANG.'.php')) {
  require_once(JL_TEMPLATE_PATH.'/language/'._JL_LANG.'.php');
}
else {
  require_once(JL_TEMPLATE_PATH.'/language/english.php');
}
// Language Selection - END

require_once('classes/refereeextension.helper.php');

require_once('extension.html.php');
$htmlHelper = new HTMLreferees();

switch($jl_func){
	//remember to set $jl_func to a dummy value if you don't want to trigger 
	//matching value in default switch
	
  case "showprojectreferees";
    // load extension config by default
    $referee_config = $joomleague->getTemplateConfig( "refereeextension.tpl");
    
    require('models'.'/'.'projectreferees.php');
    $model = new ModelProjectReferees($database, $joomleague );
    
		// get referees
    $rows = $model->getList();
    // get number of officiated games 
    $gamecount = $model->getGameCount();
    // get events
    $events_ids = explode(',',$referee_config['referee_events']);
    $events = $model->getEvents($events_ids);
	
    $mainframe->setPageTitle(_JL_REFEXT_TITLE_PROJECTREFEREES . ' - ' . $joomleague->name);
    $mainframe->appendPathWay(_JL_REFEXT_TITLE_PROJECTREFEREES . ' - ' . $joomleague->name);
    $mainframe->addCustomHeadTag( '<link rel="stylesheet" type="text/css" media="all" href="' . JL_TEMPLATE_FOLDERS_URL.'/css/JL_refext.css'. '"/>' );     
    $mainframe->addCustomHeadTag( '<script type="text/javascript" src="' . JL_TEMPLATE_FOLDERS_URL.'/js/TSorter_1.js'. '"></script>' );
    require('tmpl'.'/'.'projectreferees.php');
    $jl_func = "end";
    break;
    
  case "showprojectreferee";
    // get referee id from request  
    $referee_id = intval( mosGetParam($_REQUEST, 'id', 0) );
    if (! $referee_id) {
    	echo "Error: referee id is missing or null!";
    	break;
    }
    // load settings
    $referee_config = $joomleague->getTemplateConfig( "refereeextension.tpl");
    $page_config = $joomleague->getTemplateConfig( "projectreferee.tpl");
    
    // get model
    require('models'.'/'.'projectreferee.php');
    $model = new ModelProjectReferee($database, $joomleague, $referee_id);
    
    // get referee
    $referee = $model->getReferee();
    // get games 
    $games = $model->getGames();
    // get teams
    $teams = $joomleague->getTeamsFromMatches($games);
    
    //get events
    $events_ids = explode(',',$referee_config['referee_events']);
    $events = $model->getEvents($events_ids);
    	
    $mainframe->setPageTitle(_JL_REFEXT_TITLE_PROJECTREFEREE . ' - ' . $referee->firstname. ' ' .$referee->lastname . ' - ' . $joomleague->name);
    $mainframe->appendPathWay('<a href="'.JL_COMPONENT_LINK.'&func=showprojectReferees&p='.$joomleague->id.JL_ITEMID_SUFFIX.'">'._JL_REFEXT_TITLE_PROJECTREFEREES . ' - ' . $joomleague->name.'</a>');
    $mainframe->appendPathWay( $referee->firstname. ' ' .$referee->lastname );
    $mainframe->addCustomHeadTag( '<link rel="stylesheet" type="text/css" media="all" href="' . JL_TEMPLATE_FOLDERS_URL.'/css/JL_refext.css'. '"/>' );     
    require('tmpl'.'/'.'projectreferee.php');
    $jl_func = "end";
    break;
          
  case "showseasonreferees";
    // load extension config by default
    $referee_config = $joomleague->getTemplateConfig( "refereeextension.tpl");
    
    require('models'.'/'.'seasonreferees.php');
    $model = new ModelSeasonReferees($database, $joomleague );
    
    // get referees
    $rows = $model->getList();
    // get season
    $season = $model->getSeason();
    // get number of officiated games 
    $gamecount = $model->getGameCount();
    // get events
    $events_ids = explode(',',$referee_config['referee_events']);
    $events = $model->getEvents($events_ids);
  
    $mainframe->setPageTitle(_JL_REFEXT_TITLE_SEASONREFEREES . ' - ' . $season->name);
    $mainframe->appendPathWay(_JL_REFEXT_TITLE_SEASONREFEREES . ' - ' . $season->name);
    $mainframe->addCustomHeadTag( '<link rel="stylesheet" type="text/css" media="all" href="' . JL_TEMPLATE_FOLDERS_URL.'/css/JL_refext.css'. '"/>' );     
    $mainframe->addCustomHeadTag( '<script type="text/javascript" src="' . JL_TEMPLATE_FOLDERS_URL.'/js/TSorter_1.js'. '"></script>' );
    require('tmpl'.'/'.'seasonreferees.php');
    $jl_func = "end";
    break;
    
  case "showseasonreferee";
    // get referee id from request  
    $referee_id = intval( mosGetParam($_REQUEST, 'id', 0) );    
    if (! $referee_id) {
      echo "Error: referee id is missing or null!";
      break;
    }
    // load settings
    $referee_config = $joomleague->getTemplateConfig( "refereeextension.tpl");
    $page_config = $joomleague->getTemplateConfig( "seasonreferee.tpl");
    
    // get model
    require('models'.'/'.'seasonreferee.php');
    $model = new ModelSeasonReferee($database, $joomleague, $referee_id );
    
    // get referee
    $referee = $model->getReferee();
    // get season
    $season = $model->getSeason();
    // get games 
    $games = $model->getGames();
    // get teams
    $teams = $joomleague->getTeamsFromMatches($games);
    
    //get events
    $events_ids = explode(',',$referee_config['referee_events']);
    $events = $model->getEvents($events_ids);
      
    $mainframe->setPageTitle(_JL_REFEXT_TITLE_SEASONREFEREE . ' - ' . $referee->firstname. ' ' .$referee->lastname . ' - ' . $season->name);
    $mainframe->appendPathWay('<a href="'.JL_COMPONENT_LINK.'&func=showseasonReferees&p='.$joomleague->id.JL_ITEMID_SUFFIX.'">'._JL_REFEXT_TITLE_SEASONREFEREES . ' - ' . $season->name.'</a>');
    $mainframe->appendPathWay($referee->firstname. ' ' .$referee->lastname);
    $mainframe->addCustomHeadTag( '<link rel="stylesheet" type="text/css" media="all" href="' . JL_TEMPLATE_FOLDERS_URL.'/css/JL_refext.css'. '"/>' );     
    require('tmpl'.'/'.'seasonreferee.php');
    $jl_func = "end";
    break;
  
}

?>
